// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  traceUser: true,
  env:'aaa111-9gh9fp5ieac4de5d'
})

const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  var followlist = await db.collection('follow').where({
    _openid: wxContext.OPENID // 填入当前用户 openid
  }).get()
  followlist = followlist.data
  var followDetail = []
  for (var i = 0; i<followlist.length; i++) {
    var userDetail = await db.collection('user').where({
      _openid: followlist[i].follow
    }).get()
    await followDetail.push(userDetail.data[0])
  }
  return followDetail
}